Page({
  data: {
    isFinish: false
  },
  onLoad({ id }) {
    this.getPassport(id)
  },
  async getPassport(id) {
    const { code, data } = await wx.http.get(`/visitor/${id}`)
    // console.log(data);
    if (code !== 10000) return wx.utils.toast()
    this.setData({
      ...data
    })
  },
  // 倒计时结束
  countDownFinish() {
    this.setData({ isFinish: true })
  },
  // 分享事件
  onShareAppMessage() {
    return {
      title: '查看通行证',
      path: '/visitor_pkg/pages/passport/index',
      imageUrl: 'https://enjoy-plus.oss-cn-beijing.aliyuncs.com/images/share_poster.png'
    }
  },
  async saveImg() {
    // 获取图片临时路径
    const { path } = await wx.getImageInfo({ src: this.data.url })
    console.log(path);
    // 将图片保存到本地相册
    // this.data.url 是网络路径，saveImageToPhotosAlbum 方法不支持
    // await wx.saveImageToPhotosAlbum({ filePath: this.data.url })
    await wx.saveImageToPhotosAlbum({ filePath: path })
  }
})
